<template>
    <div class="newsinfo-container">
        <h3 class="title">{{ newsInfo.title }}</h3>
        <p class="subtitle">
            <span>发表时间: {{ newsInfo.addTime | dateFormat }}</span>
            <span>点击: {{ newsInfo.click }}次</span>
        </p>

        <hr>

        <div class="content" v-html="newsInfo.content">
        </div>

        <comment-box :id="this.id"></comment-box>
    </div>
</template>

<script>
//导入mui中Toast组件
import { Toast } from 'mint-ui';
//导入评论子组件
import comment from '../subcomponent/Comment.vue';

export default {
    data() {
        return {
            id: this.$route.params.id,   //URL地址中传递过来的id 直接挂载到data的id属性上
            newsInfo: {}
        }
    },
    methods: {
        getNewsInfo() {
            this.$http.get('vue/getNewsInfo/' + this.id).then(result => {
                if (result.body.status === 0) {
                    this.newsInfo = result.body.message;
                } else {
                    Toast('获取新闻详情失败')
                }
            });
        }

    },
    components: {
        //用来注册子组件
        'comment-box': comment
    },
    created() {
        this.getNewsInfo();
    }
}
</script>

<style lang="scss">
    .newsinfo-container {
        padding: 0 4px;
        .title {
            font-size: 16px;
            text-align: center;
            margin: 15px 0;
            color: red;
        }

        .subtitle {
            font-size: 13px;
            display: flex;
            justify-content: space-between;
            color: #226aff;
        }

        .content {
            img {
                width: 100%
            }
        }
    }
</style>